// import { md5 } from 'vux';
// const { md5 } = require('vux');
// import md5 from 'blueimp-md5';
// const md5 = require("./md5");
// console.log(md5);
module.exports = {
    getWidthHeight () {
        let w = window;
        let d = document;
        let e = d.documentElement;
        let g = d.getElementsByTagName('body')[0];
        let x = w.innerWidth || e.clientWidth || g.clientWidth;
        let y = w.innerHeight || e.clientHeight || g.clientHeight;
        return { width: x, height: y };
    },
    hasScrollBar (id) {
        id = id || 'app';
        return document.getElementById(id).scrollHeight > this.getWidthHeight().height;
    },
    getImageWH (imgUrl) {
        let img = new Image();
        img.src = imgUrl;
        return { w: img.width, h: img.height };
    },
    hidePhone (value) {
        if (!value) {
            return '';
        }
        value = value.toString();
        if (value.length !== 11) {
            return value;
        }
        return value.substring(0, 3) + '*****' + value.substring(8);
    },
    price (value, fixed) {
        value = value || 0;
        if (typeof value === 'string') {
            value = parseFloat(value);
        }
        if (fixed === undefined || fixed === null) {
            fixed = 2;
        }
        if (value < 0) {
            value = 0;
        }
        return value.toFixed(fixed);
    },
    StartsWith (str, elem) {
        if (typeof String.prototype.startsWith !== 'function') {
            return str.slice(0, elem.length) === elem;
        } else {
            return str.startsWith(elem);
        }
    },
    EndWith (str, elem) {
        if (typeof String.prototype.startsWith !== 'function') {
            return str.indexOf(elem, str.length - elem.length) !== -1;
        } else {
            return str.endWith(elem);
        }
    },
    isOwnEmpty (obj) {
        for (var name in obj) {
            if (obj.hasOwnProperty(name)) {
                return false;
            }
        }
        return true;
    },
    extendCopy (p) {
        let c = {};
        for (var i in p) {
            c[i] = p[i];
        }
        c.uber = p;
        return c;
    },
    _md5 (obj, md5) {
        var str = '';
        var arr = [];
        for (var k in obj) {
            if ((k !== 'sign') && (!/[\u4e00-\u9fa5]/g.test(obj[k]))) {
                arr.push(k);
            }
        }
        arr.sort();
        for (var i = 0; i < arr.length; i++) {
            str += obj[arr[i]];
        }
        str += 'd2a57dc1d883fd21fb9951699df71cc7';
        // return str;
        return md5(str);
    }
};
